<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .container {
        width: 100vw;
        height: 100vh;
        background: url(./banner6.png) no-repeat;
        background-size: cover;
      }
      .box {
        position: fixed;
        left: 50%;
        top: 50%;
        width: 1920px;
        height: 1080px;
        background-color: red;
        /* 缩放是以盒子的中心点为基点进行缩放的
        需要把基点调整到设备的正中间 */
        /* transform: scale(1.1); */
        transform-origin: left top;
      }
      .top {
        width: 100px;
        height: 100px;
        background-color: hotpink;
        margin-left: 50px;
      }
      .bottom {
        width: 100px;
        height: 100px;
        background-color: skyblue;
        margin-left: 50px;
        margin-top: 100px;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="box">
        <div class="top">我是祖国的</div>
        <div class="bottom">老花骨朵</div>
      </div>
    </div>
  </body>
</html>

<script>
  // 控制数据大屏的放大和缩小
  let box = document.querySelector(".box");
  box.style.transform = `scale(${getScale()}) translate(-50%,-50%)`;

  function getScale(w = 1920, h = 1080) {
    // 放大的比例 屏幕的宽度 / 原型稿的宽度
    const ww = window.innerWidth / w;
    const wh = window.innerHeight / h;
    return ww < wh ? ww : wh;
  }

  // 当视口发生变化的时候触发
  window.onresize = () => {
    box.style.transform = `scale(${getScale()}) translate(-50%,-50%)`;
  };
</script>
